$( document ).ready(function() {

    function openModal() {
        Avgrund.show("#modal");
    }

    function closeModal() {
        Avgrund.hide();
    }

    $(".close").click(function() {
        closeModal();
        return false;
    });

    $('form').validate({
        rules: {
            input_text: {
                minlength: 10,
                required: true
            }
        },
        highlight: function(element) {
            $(element).closest('.form-group').addClass('has-error');
        },
        unhighlight: function(element) {
            $(element).closest('.form-group').removeClass('has-error');
        },
        errorElement: 'span',
        errorClass: 'help-block',
        errorPlacement: function(error, element) {
            if(element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }
    });



    $("#stutter-form").submit(function() {

        input = $("#input-text").val();

        if (input.length >= 10) {

            $.ajax({
                type: "POST",
                url: "/find",
                data: "input=" + input,
                success: function (data) {
                    //alert(data);
                    openModal();
                    $(".popup-content").html(data);
                }
            });
        }
        return false;
    });
});